Micron Document




Python syntax and semantics
part 34/45 · 74.8 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Comments and docstrings

There are two ways to annotate Python code. One is by using comments to indicate what some part of the code does. Single-line comments begin with the hash character (#) and continue until the end of the line. Comments spanning more than one line are achieved by inserting a multi-line string (with """ or ''' as the delimiter on each end) that is not used in assignment or otherwise evaluated, but sits in between other statements.

Commenting a piece of code:

import sys
def getline():
return sys.stdin.readline() # Get one line and return it

Commenting a piece of code with multiple lines:

def getline():
"""This function gets one line and returns it.
As a demonstration, this is a multiline docstring.
This full string can be accessed as getline.__doc__.
"""
return sys.stdin.readline()

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────